//
//  SKUDefultQuestionUserimageNewTBCell.m
//  ZITHER
//
//  Created by weixin on 2018/9/20.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultQuestionUserimageNewTBCell.h"

@implementation SKUDefultQuestionUserimageNewTBCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    //    self.backgroundColor = [UIColor redColor];
    [self setUI];
    [self setMasonry];
    
}

-(void)setUI{
    
    [self addSubview:self.viewBack];//边界图
    [self addSubview:self.viewText];//内容
    [self addSubview:self.Cardenter];//→
    
    [self addSubview:self.labTakein];//接受报价
    [self addSubview:self.price];//价格
    
    [self addSubview:self.scrollview];//图片滑动
}

-(void)setMasonry{
    
    [self.labTakein mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(15);
        make.left.equalTo(self).offset(35);
    }];
    
    [self.viewBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self).offset(-14);
        make.bottom.equalTo(self).offset(-15);
    }];
    
    [self.Cardenter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.labTakein.mas_centerY).offset(0);
        make.right.equalTo(self).offset(-40);
        make.width.mas_equalTo(8);
        make.height.mas_equalTo(16);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.labTakein.mas_bottom).offset(5);
        make.left.equalTo(self).offset(35);
    }];
    
    [self.viewText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.price.mas_bottom).offset(5);
        make.right.equalTo(self).offset(-35);
        make.left.equalTo(self).offset(35);
    }];
    
    [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.viewText.mas_bottom).offset(5);
//        make.width.mas_equalTo(kScreenW-70);
        make.right.equalTo(self.Cardenter).offset(0);
        make.left.equalTo(self).offset(35);
        make.height.mas_equalTo(70);
        make.bottom.mas_equalTo(self).offset(-25);
    }];

}

-(void)setIndexCell:(NSInteger)index{
    if (index == 1){
        
        NSString *str = [NSString stringWithFormat:@"%@个收到的报价",self.model.receivePriceCount];
        self.labTakein.text = str;//接受报价
        [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:0.5];

        if (self.model.receiveFileList.count>0) {
            self.viewText.text = self.model.receiveSourceDesc;
            
            
            int priceInt = [self.model.receivePrice intValue];
            NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
            moneyFormatter.positiveFormat = @"###,##0";
            NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
            self.price.text = [NSString stringWithFormat:@"¥ %@",formatString];
            
            
            self.viewText.text = self.model.receiveSourceDesc;
            [self setScrImage:self.model.receiveFileList];
            [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.viewText.mas_bottom).offset(5);
                make.height.mas_equalTo(70);
            }];
        }else{
            [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.viewText.mas_bottom).offset(-10);
                make.height.mas_equalTo(0);
            }];
            self.scrollview.hidden = YES;
        }

    }else{
        [self.viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:0.5];
//        NSString *str = [NSString stringWithFormat:@"%@个更多的公开货源",self.model.openSourceCount];
        NSString *str = @"提醒更多商家向我报价";

        self.labTakein.text = str;//接受报价
        self.price.hidden = YES;
        self.scrollview.hidden = YES;
        self.viewText.hidden = YES;
        self.price.text = @"";
        self.viewText.text = @"";

        [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.viewText.mas_bottom).offset(0);
            make.height.mas_equalTo(0);
            make.bottom.mas_equalTo(self).offset(-28);
        }];
        
        [self.price mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.labTakein.mas_bottom).offset(0);
//            make.height.mas_equalTo(0);
        }];
        [self.viewText mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.height.mas_equalTo(0);
            make.top.equalTo(self.price.mas_bottom).offset(0);
        }];


//        if (self.model.fileList.count>0) {
//            [self setScrImage:self.model.fileList];
//            self.price.hidden = YES;
//            self.viewText.text = self.model.sourceDesc;
//
//            [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.viewText.mas_bottom).offset(5);
//                make.height.mas_equalTo(70);
//                make.bottom.mas_equalTo(self).offset(-25);
//            }];
//            [self.price mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.labTakein.mas_bottom).offset(5);
//            }];
//            [self.self.viewText mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.price.mas_bottom).offset(5);
//            }];
//        }else{
//            [self.scrollview mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.viewText.mas_bottom).offset(25);
//                make.height.mas_equalTo(0);
//                make.bottom.mas_equalTo(self).offset(0);
//            }];
//            [self.price mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.labTakein.mas_bottom).offset(0);
//                make.height.mas_equalTo(0);
//            }];
//            [self.self.viewText mas_updateConstraints:^(MASConstraintMaker *make) {
//                make.top.equalTo(self.price.mas_bottom).offset(0);
//            }];
//
//            self.scrollview.hidden = YES;
//
//        }
    }
    [self setNeedsLayout];

}

-(void)setScrImage:(NSArray *)arr{
    self.scrollview.hidden = NO;
//    [self.scrollview addScrImage:arr];
    
    [self.scrollview addScrImage:arr imageHeight:70];
//    [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    self.scrollview.contentSize = CGSizeMake(arr.count*68+15,0);
//gl//    for (int j = 0; j<arr.count; j++) {
//        UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
//
//        [imageV setCornerRadiusWithRadius:5 isMasks:YES];
//        imageV.backgroundColor = [UIColor randomColor];
//        imageV.contentMode = UIViewContentModeScaleAspectFill;
//
//        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,arr[j]];
//
//        [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
//
//        [self.scrollview addSubview:imageV];
//    }
    
}

-(UILabel *)labTakein{
    if (!_labTakein) {
        _labTakein = [[UILabel alloc]init];
//        _labTakein.font = [UIFont systemFontOfSize:22];
        _labTakein.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];

    }
    return _labTakein;
}

-(UIView *)viewBack{
    if (!_viewBack) {
        _viewBack = [[UILabel alloc]init];
        [_viewBack setCornerRadiusWithRadius:15 isMasks:YES];
        [_viewBack setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1];
    }
    return _viewBack;
}

- (UILabel *)viewText{
    if (!_viewText) {
        _viewText = [[UILabel alloc]init];
        _viewText.numberOfLines = 0;
        _viewText.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:13];

    }
    return _viewText;
}

- (UIImageView *)Cardenter{
    if (!_Cardenter) {
        _Cardenter = [[UIImageView alloc]init];
        _Cardenter.image = [UIImage imageNamed:@"sku_更多货源报价"];
        
    }
    return _Cardenter;
}

- (UILabel *)price{
    if (!_price) {
        _price = [[UILabel alloc]init];
        _price.textColor = baseColorTheme;
//        _price.font = [UIFont systemFontOfSize:16];
        _price.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];

        
    }
    return _price;
}


- (BaseScrollView *)scrollview{
    if (!_scrollview) {
        _scrollview = [[BaseScrollView alloc]init];
    }
    return _scrollview;
}

@end
